#include "XmlInfoMonstre.hpp"

#include <QtCore/QStringList>

#include <QtCore/QDebug>

#include "Utils/Callback.hpp"

XmlInfoMonstre XmlInfoMonstre::creeInstance( const QString &nomFichier,
                                             const QHash<QString,
                                             QString> *infos)
{
    XmlInfoMonstre retour;

    if ( ! appelleSetUnsigned( infos -> value( "id", "-1u" ),
                               &XmlInfoIdentifiant::setIdentification,
                               static_cast< XmlInfoIdentifiant* >( &retour ),
                               "id" ) )
        return XmlInfoMonstre();

    retour.setNom( infos -> value( "name", "" ) );

    if ( ! appelleSetUnsigned( infos -> value( "sadism", "-1u" ),
                               &XmlInfoCaracteristiques::setSadisme,
                               static_cast< XmlInfoCaracteristiques* >( &retour ),
                               "sadism" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "ugliness", "-1u" ),
                               &XmlInfoCaracteristiques::setLaideur,
                               static_cast< XmlInfoCaracteristiques* >( &retour ),
                               "ugliness" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "power", "-1u" ),
                               &XmlInfoCaracteristiques::setForce,
                               static_cast< XmlInfoCaracteristiques* >( &retour ),
                               "power" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "greediness", "-1u" ),
                               &XmlInfoCaracteristiques::setGourmandise,
                               static_cast< XmlInfoCaracteristiques* >( &retour ),
                               "greediness" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "control", "-1u" ),
                               &XmlInfoMonstre::setControle,
                               &retour,
                               "control" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "fight", "-1u" ),
                               &XmlInfoMonstre::setCombat,
                               &retour,
                               "fight" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "endurance", "-1u" ),
                               &XmlInfoMonstre::setEndurance,
                               &retour,
                               "endurance" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "bounty", "-1u" ),
                               &XmlInfoMonstre::setPrime,
                               &retour,
                               "bounty" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "successes", "-1u" ),
                               &XmlInfoMonstre::setNbrSucces,
                               &retour,
                               "successes" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "failures", "-1u" ),
                               &XmlInfoMonstre::setNbrEchecs,
                               &retour,
                               "failures" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "devoured", "-1u" ),
                               &XmlInfoMonstre::setNbrDevores,
                               &retour,
                               "devoured" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "firePrize", "-1u" ),
                               &XmlInfoMonstre::setPrixRevente,
                               &retour,
                               "firePrize" ) )
        return XmlInfoMonstre();

    retour . setUrlAffichage( infos -> value( "swfjs", "" ) );

    if ( ! appelleSetUnsigned( infos -> value( "fatigue", "-1u" ),
                               &XmlInfoMonstre::setNbrHeuresRepos,
                               &retour,
                               "fatigue" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "contract", "-1u" ),
                               &XmlInfoMonstre::setIdContratEffectue,
                               &retour,
                               "contract" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "escort", "-1u" ),
                               &XmlInfoMonstre::setIdContratEscorte,
                               &retour,
                               "escort" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "attack", "-1u" ),
                               &XmlInfoMonstre::setIdAttaque,
                               &retour,
                               "attack" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "racket", "-1u" ),
                               &XmlInfoMonstre::setIdRacket,
                               &retour,
                               "racket" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "propaganda", "-1u" ),
                               &XmlInfoMonstre::setIdPropagande,
                               &retour,
                               "propaganda" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "match", "-1u" ),
                               &XmlInfoMonstre::setIdMatch,
                               &retour,
                               "match" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetListUnsigned( infos -> value( "permanentItems", "" ),
                                   &XmlInfoMonstre::setEquipementPermanent,
                                   &retour,
                                   "permanentItems" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetListUnsigned( infos -> value( "contractItems", "" ),
                                   &XmlInfoMonstre::setEquipementTemporaire,
                                   &retour,
                                   "contractItems" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetUnsigned( infos -> value( "watchSpas", "-1u" ),
                               &XmlInfoMonstre::setNbrSpas,
                               &retour,
                               "watchSpas" ) )
        return XmlInfoMonstre();

    if ( ! appelleSetBool( infos -> value( "isMblMonster", "false" ),
                           &XmlInfoMonstre::setSpecialisteMbl,
                           &retour,
                           "isMblMonster" ) )
        return XmlInfoMonstre();

    retour . setNomFichier( nomFichier );

    return retour;
}

XmlInfoMonstre::XmlInfoMonstre()
    : XmlInfoCaracteristiques(),
      Controle( -1u ), Combat( -1u ), Endurance( -1u ),
      Prime( -1u )
{}

XmlInfoMonstre::XmlInfoMonstre( const QString& nomFichier,
                                const unsigned& id,
                                const QString& nom,
                                const unsigned& sadisme,
                                const unsigned& laideur,
                                const unsigned& force,
                                const unsigned& gourmandise,
                                const unsigned& controle,
                                const unsigned& combat,
                                const unsigned& endurance,
                                const unsigned& prime )
    : XmlInfoCaracteristiques( nomFichier, id, nom, sadisme, laideur, force,
          gourmandise ),
      Controle( controle ), Combat( combat ), Endurance( endurance ),
      Prime( prime )
{}

XmlInfoMonstre::XmlInfoMonstre( const XmlInfoMonstre& monstre )
    : XmlInfoCaracteristiques( monstre ),
      Controle( monstre.controle() ),
      Combat( monstre.combat() ),
      Endurance( monstre.endurance() ),
      Prime( monstre.prime() ),
      NbrSucces( monstre.nbrSucces() ),
      NbrEchecs( monstre.nbrEchecs() ),
      NbrDevores( monstre.nbrDevores() ),
      PrixRevente( monstre.prixRevente() ),
      NiveauEntrainement( monstre.niveauEntrainement() ),
      NiveauFusion( monstre.niveauFusion() ),
      SpecialisteMbl( monstre.specialisteMbl() ),
      UrlAffichage( monstre.urlAffichage() ),
      NbrHeuresRepos( monstre.nbrHeuresRepos() ),
      IdContratEffectue( monstre.idContratEffectue() ),
      IdContratEscorte( monstre.idContratEscorte() ),
      IdAttaque( monstre.idAttaque() ),
      IdMatch( monstre.idMatch() ),
      NbrSpas( monstre.nbrSpas() )
{
    EquipementPermanent = *monstre.equipementPermanent();
    EquipementTemporaire = *monstre.equipementTemporaire();
}

XmlInfoMonstre::~XmlInfoMonstre()
{}

XmlInfoMonstre& XmlInfoMonstre::operator=( const XmlInfoMonstre& monstre )
{
    if ( &monstre != this)
    {
        this -> XmlInfoCaracteristiques::operator=( monstre );

        Controle             = monstre.controle();
        Combat               = monstre.combat();
        Endurance            = monstre.endurance();
        Prime                = monstre.prime();
        NbrSucces            = monstre.nbrSucces();
        NbrEchecs            = monstre.nbrEchecs();
        NbrDevores           = monstre.nbrDevores();
        PrixRevente          = monstre.prixRevente();
        NiveauEntrainement   = monstre.niveauEntrainement();
        NiveauFusion         = monstre.niveauFusion();
        UrlAffichage         = monstre.urlAffichage();
        NbrHeuresRepos       = monstre.nbrHeuresRepos();
        IdContratEffectue    = monstre.idContratEffectue();
        IdContratEscorte     = monstre.idContratEscorte();
        IdAttaque            = monstre.idAttaque();
        IdMatch              = monstre.idMatch();
        EquipementPermanent  = *monstre.equipementPermanent();
        EquipementTemporaire = *monstre.equipementTemporaire();
        NbrSpas              = monstre.nbrSpas();
    }

    return *this;
}

void XmlInfoMonstre::afficheInstance() const
{
    qDebug() << QObject::trUtf8( "Monstre : %1, id = %2." ).arg( nom() + ( specialisteMbl() ? " (MBL)" : "" ) ).arg( identification() );
    qDebug() << QObject::trUtf8( "Sadisme = %1, Laideur = %2, Force = %3, Gourmandise = %4" ).arg( sadisme() ).arg( laideur() ).arg( force() ).arg( gourmandise() );
    qDebug() << QObject::trUtf8( "Contrôle = %1, Combat = %2, Endurance = %3, Prime = %4" ).arg( controle() ).arg( combat() ).arg( endurance() ).arg( prime() );
}

const unsigned& XmlInfoMonstre::caracteristique( const EnumCaracteristique &car ) const
{
    switch ( car )
    {
    case CarSadisme:
    case CarLaideur:
    case CarForce:
    case CarGourmandise:
        return XmlInfoCaracteristiques::caracteristique( car );
    default:
        return controle();
    }
}

const unsigned& XmlInfoMonstre::caracteristique( const unsigned &car ) const
{
    return caracteristique( static_cast< EnumCaracteristique >( car & 5 ) );
}

unsigned& XmlInfoMonstre::rCaracteristique( const EnumCaracteristique &car )
{
    switch ( car )
    {
    case CarSadisme:
        return Sadisme;
    case CarLaideur:
        return Laideur;
    case CarForce:
        return Force;
    case CarGourmandise:
        return Gourmandise;
    case CarControle:
        return Controle;
    default:
        return Controle;
    }
}

unsigned& XmlInfoMonstre::rCaracteristique( const unsigned &car )
{
    return rCaracteristique( static_cast< EnumCaracteristique >( car % 5 ) );
}

const unsigned& XmlInfoMonstre::controle() const
{
    return Controle;
}

const unsigned& XmlInfoMonstre::combat() const
{
    return Combat;
}

const unsigned& XmlInfoMonstre::endurance() const
{
    return Endurance;
}

const unsigned& XmlInfoMonstre::prime() const
{
    return Prime;
}

const unsigned& XmlInfoMonstre::nbrSucces() const
{
    return NbrSucces;
}

const unsigned& XmlInfoMonstre::nbrEchecs() const
{
    return NbrEchecs;
}

const unsigned& XmlInfoMonstre::nbrDevores() const
{
    return NbrDevores;
}

const unsigned& XmlInfoMonstre::prixRevente() const
{
    return PrixRevente;
}

const unsigned& XmlInfoMonstre::niveauEntrainement() const
{
    return NiveauEntrainement;
}

const unsigned& XmlInfoMonstre::niveauFusion() const
{
    return NiveauFusion;
}

const bool& XmlInfoMonstre::specialisteMbl() const
{
    return SpecialisteMbl;
}

const QString& XmlInfoMonstre::urlAffichage() const
{
    return UrlAffichage;
}

const unsigned& XmlInfoMonstre::nbrHeuresRepos() const
{
    return NbrHeuresRepos;
}

const unsigned& XmlInfoMonstre::idContratEffectue() const
{
    return IdContratEffectue;
}

const unsigned& XmlInfoMonstre::idContratEscorte() const
{
    return IdContratEscorte;
}

const unsigned& XmlInfoMonstre::idAttaque() const
{
    return IdAttaque;
}

const unsigned& XmlInfoMonstre::idRacket() const
{
    return IdRacket;
}

const unsigned& XmlInfoMonstre::idPropagande() const
{
    return IdPropagande;
}

const unsigned& XmlInfoMonstre::idMatch() const
{
    return IdMatch;
}

const QList< unsigned >* XmlInfoMonstre::equipementPermanent() const
{
    return &EquipementPermanent;
}

const QList< unsigned >* XmlInfoMonstre::equipementTemporaire() const
{
    return &EquipementTemporaire;
}

const unsigned& XmlInfoMonstre::nbrSpas() const
{
    return NbrSpas;
}

void XmlInfoMonstre::setControle( const unsigned& controle )
{
    Controle = controle;
}

void XmlInfoMonstre::setCombat( const unsigned& combat )
{
    Combat = combat;
}

void XmlInfoMonstre::setEndurance( const unsigned& endurance )
{
    Endurance = endurance;
}

void XmlInfoMonstre::setPrime( const unsigned& prime )
{
    Prime = prime;
}

void XmlInfoMonstre::setNbrSucces( const unsigned& nbrSucces )
{
    NbrSucces = nbrSucces;
}

void XmlInfoMonstre::setNbrEchecs( const unsigned& nbrEchecs )
{
    NbrEchecs = nbrEchecs;
}

void XmlInfoMonstre::setNbrDevores( const unsigned& nbrDevores )
{
    NbrDevores = nbrDevores;
}

void XmlInfoMonstre::setPrixRevente( const unsigned& prixRevente )
{
    PrixRevente = prixRevente;
}

void XmlInfoMonstre::setNiveauEntrainement( const unsigned& nivEntrainement )
{
    NiveauEntrainement = nivEntrainement;
}

void XmlInfoMonstre::setNiveauFusion( const unsigned& nivFusion )
{
    NiveauFusion = nivFusion;
}

void XmlInfoMonstre::setSpecialisteMbl( const bool &specialisteMbl )
{
    SpecialisteMbl = specialisteMbl;
}

void XmlInfoMonstre::setUrlAffichage( const QString& urlAffichage )
{
    UrlAffichage = urlAffichage;
}

void XmlInfoMonstre::setNbrHeuresRepos( const unsigned& nbrHeuresRepos )
{
    NbrHeuresRepos = nbrHeuresRepos;
}

void XmlInfoMonstre::setIdContratEffectue( const unsigned& idContrat )
{
    IdContratEffectue = idContrat;
}

void XmlInfoMonstre::setIdContratEscorte( const unsigned& idEscorte )
{
    IdContratEscorte = idEscorte;
}

void XmlInfoMonstre::setIdAttaque( const unsigned& idAttaque )
{
    IdAttaque = idAttaque;
}

void XmlInfoMonstre::setIdRacket( const unsigned& idRacket )
{
    IdRacket = idRacket;
}

void XmlInfoMonstre::setIdPropagande( const unsigned& idPropagande )
{
    IdPropagande = idPropagande;
}

void XmlInfoMonstre::setIdMatch( const unsigned& idMatch )
{
    IdMatch = idMatch;
}

void XmlInfoMonstre::setEquipementPermanent( const QList< unsigned >& permanent )
{
    EquipementPermanent = permanent;
}

void XmlInfoMonstre::setEquipementTemporaire( const QList< unsigned >& temporaire )
{
    EquipementTemporaire = temporaire;
}

void XmlInfoMonstre::setNbrSpas( const unsigned& nbrSpas )
{
    NbrSpas = nbrSpas;
}
